"use strict";
cc._RF.push(module, 'd2172RdtbhJ47cUFRF/Qx6I', 'uiModule');
// scripts/engines/modules/uiModule.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.UI_Z_INDEX = void 0;
var superModule_1 = require("./superModule");
var o1MessageBox_1 = require("./uiModule/o1MessageBox");
var o1DialogBox_1 = require("./uiModule/o1DialogBox");
var o1Loading_1 = require("./uiModule/o1Loading");
var gameEngine_1 = require("../gameEngine");
var RewardView_1 = require("../../O1ModuleRes/control/RewardView");
var addUserProp_1 = require("../../O1ModuleRes/control/addUserProp");
var MainRoot_1 = require("../../Game/MainRoot");
var data_control_1 = require("../libs/data_control");
var gameConfig_1 = require("../configs/gameConfig");
var UI_Z_INDEX;
(function (UI_Z_INDEX) {
    UI_Z_INDEX[UI_Z_INDEX["NORMAL"] = 0] = "NORMAL";
    UI_Z_INDEX[UI_Z_INDEX["DIALOG"] = 10] = "DIALOG";
    UI_Z_INDEX[UI_Z_INDEX["MESSAGE"] = 11] = "MESSAGE";
    UI_Z_INDEX[UI_Z_INDEX["LOADING"] = 12] = "LOADING";
})(UI_Z_INDEX = exports.UI_Z_INDEX || (exports.UI_Z_INDEX = {}));
var uiModule = /** @class */ (function (_super) {
    __extends(uiModule, _super);
    function uiModule() {
        var _this = _super.call(this) || this;
        _this.m_className = 'UI模块';
        //
        _this.m_pathFrameBundle = 'o1ModuleRes';
        //
        _this.m_pathGameBundle = 'gameBundle';
        //
        _this.m_pathPreloadFrame = 'preload/frame';
        //
        _this.m_pathPreloadGame = 'preload';
        _this.InfinityModel = 'user-is-infinity';
        _this.InfinityPower_Key = 'user-logintime';
        //全局框架bundle
        _this.m_frameBundle = null;
        //游戏公用bundle
        _this.m_gameBundle = null;
        //高斯模糊
        _this.m_uiBgTexture = null;
        _this.m_uiBgSpriteFrame = null;
        _this.isOKRightOrUnderlie = true;
        // CP -按钮交换位置模式   DS -取消按钮延迟显示模式   CC -默认勾选看视频领奖励模式
        _this.dlgBoxName_VD = ["o1DialogBox_VD_CP", "o1DialogBox_VD_DS", "o1DialogBox_VD_CC"];
        _this.m_loadingNode = null;
        _this.m_loadingOver = false;
        return _this;
    }
    //设置高模
    uiModule.prototype.setGaussianMode = function (bgNode) {
        return;
        //暂时不需要
        // //
        // if (!bgNode.isValid) return;
        // //
        // this.changeCurrCanvasPicture();
        // //高斯模糊
        // if (bgNode) {
        //     bgNode.getComponent(cc.Sprite).spriteFrame = this.m_uiBgSpriteFrame;
        // }
        // // }, 0.01666);
    };
    // private changeCurrCanvasPicture() {
    //     if (this.m_uiBgTexture) {
    //         delete this.m_uiBgTexture;
    //     }
    //     if (this.m_uiBgSpriteFrame) {
    //         delete this.m_uiBgSpriteFrame;
    //     }
    //     //
    //     this.m_uiBgTexture = new cc.RenderTexture();
    //     this.m_uiBgTexture.initWithElement(cc.game.canvas);
    //     this.m_uiBgSpriteFrame = new cc.SpriteFrame(this.m_uiBgTexture);
    // }
    //预加载框架资源路径
    uiModule.prototype.getFrameBundlePreloadResPath = function () {
        return this.m_pathPreloadFrame;
    };
    //预加载游戏资源路径
    uiModule.prototype.getGameBundlePreloadResPath = function () {
        return this.m_pathPreloadGame;
    };
    uiModule.prototype.preLoadModules = function () {
        return __awaiter(this, void 0, Promise, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, _super.prototype.preLoadModules.call(this)];
            });
        });
    };
    uiModule.prototype.loadModule = function () {
        return __awaiter(this, void 0, Promise, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, _super.prototype.loadModule.call(this)];
            });
        });
    };
    /**
     * 显示消息
     * @param message 消息文本
     * @param parentNode 父节点
     * @param 显示时间
     * */
    uiModule.prototype.showMessageBox = function (message, parentNode, showTime) {
        if (parentNode === void 0) { parentNode = null; }
        if (showTime === void 0) { showTime = 2; }
        parentNode = parentNode || MainRoot_1.default.UIRoot;
        this.m_frameBundle.load(this.m_pathPreloadFrame + "/o1MessageBox", cc.Prefab, function (error, assets) {
            if (error) {
                console.error('#40错误 错误消息框预制体', error);
                return;
            }
            //
            var node = cc.instantiate(assets);
            node.getComponent(o1MessageBox_1.default).showMessageBox(message, showTime);
            parentNode.addChild(node, UI_Z_INDEX.MESSAGE);
        });
    };
    /**添加桌面 */
    uiModule.prototype.addShortcutBox = function (parentNode) {
        //字节跳动 字节跳动lite 和西瓜拒审 关闭
        if (parentNode === void 0) { parentNode = null; }
        if (!MainRoot_1.default.isShortcutOpen()) {
            return;
        }
        parentNode = parentNode || MainRoot_1.default.UIRoot;
        this.m_frameBundle.load(this.m_pathPreloadFrame + "/addDestokPage", cc.Prefab, function (error, assets) {
            if (error) {
                console.error('#40错误 错误消息框预制体', error);
                return;
            }
            //
            var node = cc.instantiate(assets);
            parentNode.addChild(node, UI_Z_INDEX.MESSAGE);
        });
    };
    /**
     * 显示模态对话框 看视频按钮请注意文本长度 要 与取消文本所在按钮同大小
     * @param title 标题
     * @param message 文本
     * @param isCancelOk 是否有取消按钮
     * @param clickCallBack 点击回调 是否确定
     * @param parentNode 父节点
     * @param okButtonText 确定按钮自定义文本
     * @param cancelButtonText 取消按钮自定义文本
     * @param lookVideoCount 观看视频次数
     * @param ovVideoAdPatternIndex ov平台激励视频弹窗样式选择，无输入则随机： 0 -CP  1 -DS  2 -CC
     * @param lookVideoSource 观看视频目的
     * */
    uiModule.prototype.showDialogBox = function (title, message, isCancelOk, clickCallBack, parentNode, okButtonText, cancelButtonText, lookVideoCount, ovVideoAdPatternIndex, lookVideoSource) {
        if (isCancelOk === void 0) { isCancelOk = false; }
        if (parentNode === void 0) { parentNode = null; }
        if (ovVideoAdPatternIndex === void 0) { ovVideoAdPatternIndex = null; }
        parentNode = parentNode || MainRoot_1.default.UIRoot;
        //
        //
        this.m_frameBundle.load(this.m_pathPreloadFrame + "/o1DialogBox", cc.Prefab, function (error, assets) {
            if (error) {
                console.error('#40错误 错误对话框预制体', error);
                return;
            }
            var node = cc.instantiate(assets);
            node.getComponent(o1DialogBox_1.default).showDialogBox(title, message, isCancelOk, clickCallBack, okButtonText, cancelButtonText, lookVideoCount, lookVideoSource);
            parentNode.addChild(node, UI_Z_INDEX.DIALOG);
        });
    };
    /**
     * 显示加载
     * @param parentNode 父节点
     * @param loadingText 加载文本
     * */
    uiModule.prototype.showLoading = function (parentNode, loadingText) {
        if (parentNode === void 0) { parentNode = null; }
        if (loadingText === void 0) { loadingText = '正在加载'; }
        return __awaiter(this, void 0, void 0, function () {
            var _this = this;
            return __generator(this, function (_a) {
                return [2 /*return*/, new Promise(function (resolve) {
                        _this.m_loadingOver = false;
                        parentNode = parentNode || MainRoot_1.default.UIRoot;
                        _this.m_frameBundle.load(_this.m_pathPreloadFrame + "/o1Loading", cc.Prefab, function (error, assets) { return __awaiter(_this, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                if (error) {
                                    console.error('#40错误 错误对话框加载', error);
                                    return [2 /*return*/, resolve()];
                                }
                                // if (this.m_loadingOver) {
                                //     this.hideLoading();
                                //     return resolve();
                                // }
                                if (this.m_loadingNode) {
                                    if (this.m_loadingNode.isValid) {
                                        this.m_loadingNode.removeFromParent(false);
                                    }
                                    else {
                                        this.m_loadingNode.destroy();
                                        this.m_loadingNode = null;
                                    }
                                }
                                if (!this.m_loadingNode) {
                                    this.m_loadingNode = cc.instantiate(assets);
                                }
                                this.m_loadingNode.getComponent(o1Loading_1.default).showLoading(loadingText);
                                parentNode.addChild(this.m_loadingNode, UI_Z_INDEX.LOADING);
                                this.m_loadingNode.setPosition(0, 0);
                                // await this.m_loadingNode.getChildByName("loading").getComponent(loadingAni).fontAni();
                                console.log("重新加载loading也", this.m_loadingNode.x, this.m_loadingNode.y);
                                resolve();
                                return [2 /*return*/];
                            });
                        }); });
                    })];
            });
        });
    };
    /**
     * 展示无限体力界面
     * @param showProbability 展示无限体力的概率 1为必现  已经有无限体力不会展示
     * @param parentNode 父节点
     */
    uiModule.prototype.showInfinityPower = function (showProbability, parentNode) {
        var that = this;
        if (window['tt']) {
            window['tt'].checkShortcut({
                success: function (res) {
                    console.info("success快捷方式 showInfinityPower", res);
                    if (res.status.exist) {
                        console.info("success快捷方式存在");
                    }
                    else {
                        console.info("success快捷方式不存在");
                        that.addShortcutBox();
                    }
                    //获取快捷方式是否存在 res.status.exist
                },
                fail: function (res) {
                    console.info("fail快捷方式检查showInfinityPower", res.errMsg);
                }
            });
        }
        var dateOld = gameEngine_1.default.getServices().localStorageSrv.getStorage(this.InfinityPower_Key);
        if (dateOld) {
            var rand = Math.random();
            if (Number(gameEngine_1.default.getServices().localStorageSrv.getStorage(this.InfinityModel)) == 0) {
                if (rand < showProbability) {
                    this.createAndShowInfinityPower(parentNode);
                }
            }
            else {
                this.showMessageBox("\u65E0\u9650\u7545\u73A9 " + data_control_1.default.MinusToHours(gameConfig_1.default.INFINITY_POWER_VIDEO_HAND_TIME) + " \u5DF2\u89E3\u9501");
            }
        }
        else {
            //todo 第一次登陆
            gameEngine_1.default.getServices().localStorageSrv.setStorage(this.InfinityPower_Key, Date.now());
            this.createAndShowInfinityPower(parentNode);
        }
    };
    //电子邮件puhalskijsemen@gmail.com
    //源码网站 开vpn全局模式打开 http://web3incubators.com/
    //电报https://t.me/gamecode999
    /**
     * 获取金币体力钻石等
     * @param rewardType 奖励类型
     * @param rewardCount 数量
     * @param parentNode 父节点
     */
    uiModule.prototype.showUserPropGet = function (rewardType, rewardCount, parentNode, overCb) {
        var that = this;
        if (window['tt']) {
            window['tt'].checkShortcut({
                success: function (res) {
                    console.info("success快捷方式 showUserPropGet", res);
                    if (res.status.exist) {
                        console.info("success快捷方式存在");
                    }
                    else {
                        console.info("success快捷方式不存在");
                        that.addShortcutBox();
                    }
                    //获取快捷方式是否存在 res.status.exist
                },
                fail: function (res) {
                    console.info("fail快捷方式检查showUserPropGet", res.errMsg);
                }
            });
        }
        this.showFramePrefab('preload/control/addUserProp', parentNode, true, function (node) {
            node.getComponent(addUserProp_1.default).setData(rewardType, rewardCount);
            overCb && overCb();
        });
    };
    /***
     * 显示获得的奖励
     * @param rewardType 奖励类型
     * @param rewardCount 奖励数量
     * @param titleString 奖励标题
     * @param customSpriteFrame 奖励图片
     * @param parentNode 父节点
     * @constructor
     */
    uiModule.prototype.showGetRewarded = function (rewardType, rewardCount, titleString, customSpriteFrame, parentNode) {
        parentNode = parentNode || MainRoot_1.default.UIRoot;
        this.showFramePrefab('preload/control/RewardView', parentNode, true, function (node) {
            node.getComponent(RewardView_1.default).OnShowReward(rewardType, rewardCount, titleString, customSpriteFrame);
        });
    };
    /**
     * 展示无限体力界面
     * @param parentNode 父节点
     */
    uiModule.prototype.createAndShowInfinityPower = function (parentNode) {
        parentNode = parentNode || MainRoot_1.default.UIRoot;
        this.showFramePrefab('preload/infinitypower', parentNode, false, function (node) {
        });
        // this.m_frameBundle.load('preload/infinitypower', cc.Prefab, (error, assets: cc.Prefab) => {
        //     if (error) {
        //         console.error("无限体力预制体加载失败", error);
        //         return;
        //     }
        //     let InfinityPower = cc.instantiate(assets);
        //     InfinityPower.scale = 0.1;
        //     parentNode.addChild(InfinityPower);//展示无限体力页面
        //     cc.tween(InfinityPower).to(0.3, {scale: 1}, {easing: "backOut"}).start();
        // });
    };
    /**
     * 隐藏加载
     * */
    uiModule.prototype.hideLoading = function () {
        console.log("#关闭loading异常");
        this.m_loadingNode && this.m_loadingNode.isValid && this.m_loadingNode.destroy();
        this.m_loadingNode = null;
        this.m_loadingOver = true;
    };
    uiModule.prototype.getFrameBundlePath = function () {
        return this.m_pathFrameBundle;
    };
    uiModule.prototype.getGameBundlePath = function () {
        return this.m_pathGameBundle;
    };
    uiModule.prototype.setFrameBundle = function (bundle) {
        this.m_frameBundle = bundle;
    };
    uiModule.prototype.setGameBundle = function (bundle) {
        this.m_gameBundle = bundle;
    };
    uiModule.prototype.getFrameBundle = function () {
        return this.m_frameBundle;
    };
    uiModule.prototype.getGameBundle = function () {
        return this.m_gameBundle;
    };
    /**
     * 显示预制体
     * @param inPrefabPath 预制体在子包的路径
     * @param parentNode 父节点
     * @param isShowLoading 显示/不显示 加载条
     * @param addedCallback 成功回调
     */
    uiModule.prototype.showFramePrefab = function (inPrefabPath, parentNode, isShowLoading, addedCallback) {
        var _this = this;
        //c
        parentNode = parentNode || MainRoot_1.default.UIRoot;
        //
        if (isShowLoading) {
            this.showLoading();
        }
        this.m_frameBundle.load(inPrefabPath, cc.Prefab, function (error, assets) {
            if (isShowLoading) {
                _this.hideLoading();
            }
            if (error) {
                console.error('#446 错误 ui加载预制体', inPrefabPath);
                return;
            }
            //
            if (parentNode && parentNode.isValid) {
                var node = cc.instantiate(assets);
                parentNode.addChild(node);
                addedCallback && addedCallback(node);
            }
            else {
                console.error('#453 错误 ui 父节点已失效', inPrefabPath, Date.now());
            }
        });
    };
    /**
     * 显示隐藏对话框动画
     * @param node 目标节点
     * @param isShow 显示为真 隐藏为假
     * @param cb 动画完成回调
     */
    uiModule.prototype.showHideDialogAnimation = function (node, isShow, cb) {
        //
        if (node && node.isValid) {
            var SCALE_TIME = 0.26;
            if (isShow) {
                node.scale = 0;
                cc.tween(node)
                    .parallel(cc.tween(node).to(SCALE_TIME, { scale: 1 }), cc.tween(node)
                    .by(SCALE_TIME * 0.45, { y: 250 }, { easing: 'cubicOut' })
                    .by(SCALE_TIME * 0.55, { y: -250 }, { easing: 'cubicIn' }))
                    .call(cb)
                    .start();
            }
            else {
                cc.tween(node)
                    .parallel(cc.tween(node).to(SCALE_TIME, { scale: 0 }), cc.tween(node)
                    .by(SCALE_TIME * 0.55, { y: 250 }, { easing: 'cubicOut' })
                    .by(SCALE_TIME * 0.45, { y: -250 }, { easing: 'cubicIn' }))
                    .call(cb)
                    .start();
            }
        }
    };
    return uiModule;
}(superModule_1.default));
exports.default = uiModule;

cc._RF.pop();